﻿using HandyControl.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Common.Device.Views
{
    /// <summary>
    /// TestChannelFullView.xaml 的交互逻辑
    /// </summary>
    public partial class TestChannelFullView : UserControl
    {
        static HandyControl.Controls.PopupWindow window;
        private TestChannelFullView()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 显示完整测试表
        /// </summary>
        /// <param name="viewModel"></param>
        public static void Show(ViewModels.TestListViewModel viewModel)
        {
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                //弹窗显示
                TestChannelFullView view = new TestChannelFullView();
                window = new HandyControl.Controls.PopupWindow
                {
                    ShowBorder = false,
                    ShowTitle = false,
                    Background = Brushes.Transparent,
                    PopupElement = view,
                    WindowStartupLocation = WindowStartupLocation.CenterScreen,
                    AllowsTransparency = true,
                    WindowStyle = WindowStyle.None,
                    MinWidth = 0,
                    MinHeight = 0
                };
                view.Loaded += (s, e2) =>
                {
                    view.DataContext = viewModel; 
                    view.log.Content=new Common.View.Controls.ExRichTextBox( viewModel.document);
                };
                window.ShowDialog();
            }));
        }
        private void Grid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                //触摸屏触发时跳过
                if (e.StylusDevice != null)
                {
                    e.Handled = true;
                }
                else
                {
                    window?.DragMove();
                }
            }
            catch (Exception)
            {

                //throw;
            }

        }
        //触摸屏触发
        private void Grid_PreviewTouchDown(object sender, TouchEventArgs e)
        {
            try
            {
                window?.DragMove();
            }
            catch (Exception)
            {

                // throw;
            }

        }
        private void closeClick(object sender, RoutedEventArgs e)
        {
            window?.Close();
        }
    }
}
